package com.bitcoin.scheduler.repository;

import com.bitcoin.scheduler.domain.Bcc;
import com.bitcoin.scheduler.domain.BccBatch;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

/**
 * @author Jason
 * @date 2018/3/29
 **/
public interface BccBatchDao extends JpaRepository<BccBatch, String> {

    List<BccBatch> findByBatchTypeAndBatchStateOrderByEndDateDesc(String bathType, String batchState);

    /**
     * 根据批次类型更新批次过期批次
     *
     * @param batchType 批次类型
     */
    @Query("UPDATE BccBatch SET batchState ='" + Bcc.BathState.EXPIRE + "' WHERE batchType=:batchType")
    @Modifying
    void updateExpireByBatchType(@Param("batchType") String batchType);

    /**
     * 根据批次号查找唯一批次
     *
     * @param batchNo 批次号码
     * @return 批次详细信息
     */
    BccBatch findByBatchNo(String batchNo);

    BccBatch findTop1ByBatchTypeAndBatchStateOrderByEndDateDesc(String crawlBasicInfo, String expire);
}
